package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.dtos.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author Lijx
 * @Date 2024-07-21 14:23
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 分页查询自媒体素材列表
     * @param materialDto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult getMaterialPage(@RequestBody WmMaterialDto materialDto){
        log.info("分页查询自媒体素材列表接口，入参={}",materialDto);

        return wmMaterialService.getMaterialPage(materialDto);
    }

    /**
     * 上传素材
     * @param multipartFile
     * @return
     */
    @PostMapping("/upload_picture")
    public ResponseResult upload(MultipartFile multipartFile){
        log.info("上传素材接口，入参={}",multipartFile.getOriginalFilename());
        return wmMaterialService.upload(multipartFile);
    }

    /**
     * 收藏素材
     * @param id
     * @return
     */
    @GetMapping("collect/{id}")
    public ResponseResult updateCollect(@PathVariable Integer id){
        log.info("收藏素材接口，入参id={}",id);
        return wmMaterialService.updateCollect(id);
    }

    /**
     * 取消收藏素材
     * @param id
     * @return
     */
    @GetMapping("cancel_collect/{id}")
    public ResponseResult updateCanceCollect(@PathVariable Integer id){
        log.info("收藏素材接口，入参id={}",id);
        return wmMaterialService.updateCollect(id);
    }

    /**
     * 删除素材
     * @return
     */
    @GetMapping("/del_picture/{id}")
    public ResponseResult deleteMaterial(@PathVariable Integer id){
        log.info("删除素材接口，入参id={}",id);
        return wmMaterialService.deleteMaterial(id);
    }
}
